package Test;

import vo.Student;
import vo.music;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Test2 {

    private static void test1(){
        Integer reduce = Stream.of(1, 2, 3)
                .reduce(0, (acc, e) -> acc + e);
        System.out.println(reduce);
    }

    private static void test2(){
        List<Integer> list = Arrays.asList(1, 2, 3);
    }

    private static int test3(Stream<Integer> numbers){
        return numbers.reduce(0,(k,v) ->k+v);
    }

    private static void test4(){
        List<Student> list = Arrays.asList(new Student(1, "ff","中国"),
                new Student(2, "bb","美国"),
                new Student(3,"cc","法国"),
                new Student(4,"dd","日本"));

        List<String> collect = list.stream().flatMap(e -> Stream.of(e.getName(), e.getNationality())).collect(Collectors.toList());
        collect.forEach(System.out::println);

    }

    public static int test5(String st){
        return (int) st.chars().filter(Character::isLowerCase).count();
    }

    public static void test6(){
        List<String> list = Arrays.asList("3", "6", "8",
                "14", "15");

        list.stream().mapToInt(e ->Integer.parseInt(e))
                .filter(e ->e %3==0)
                .forEach(System.out::println);
    }

    public static void test7(){
        List<music> list = Arrays.asList(new music("1", "小米"),
                new music("2", "小米"),
                new music("3", "小米"));

        IntSummaryStatistics intSummaryStatistics = list.stream().mapToInt(e -> Integer.parseInt(e.getId())).summaryStatistics();
        long sum = intSummaryStatistics.getSum();
        System.out.println(sum);


    }

    //mapToInt
    public static void test8(){
        List<Student> list = Arrays.asList(new Student(1, "ff","中国"),
                new Student(2, "bb","美国"),
                new Student(3,"cc","法国"),
                new Student(4,"dd","日本"));

        long sum = list.stream().mapToInt(e -> e.getId()).count();
        System.out.println(sum);

        IntSummaryStatistics intSummaryStatistics = list.stream().mapToInt(e -> e.getId()).summaryStatistics();
        System.out.println(intSummaryStatistics.getMin());

    }

    public static void main(String[] args) {
        test8();
    }
}
